package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.jitui.JiTuiMobileOnlineData;
import com.ucredit.babel.common.model.jitui.JiTuiMobileOnlineRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 极推在网时长
 *
 * @author renzhanzheng
 */

public class JiTuiMobileOnlineParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 极推在网时长
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        JiTuiMobileOnlineRecord obj = (JiTuiMobileOnlineRecord)model;
        JiTuiMobileOnlineData data = obj.getData();

        StringBuilder sb = getBaseInfo(obj, successful);
        //响应说明
        sb.append(data.getMsg() == null ? "" : data.getMsg()).append(CRT001);
        //状态码
        sb.append(data.getCode() == null ? "" : data.getCode()).append(CRT001);
        //在网时长范围起始值
        sb.append(data.getRangeStart()== null ? "" : data.getRangeStart() ).append(CRT001);
        //携号转网的返回对应的运营商
        sb.append(data.getProvider() == null ? "" : data.getProvider()).append(CRT001);
        //是否收费
        sb.append(data.getFee()).append(CRT001);
        //在网时长范围结束值
        sb.append(data.getRangeEnd() == null ? "" : data.getRangeEnd()).append(CRT001);

        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;

    }

    @Override
    public String getTableName() {
        return "kafka_babel_jitui_onlinetime_inc";
    }

    @Override
    public String getType() {
        return RecordType.JITUI_MOBILEONLINE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "极推在网时长";
    }
}
